package com.wigem.dic.service;

import com.wigem.dic.entity.DicIndustryEntity;
import com.wigem.dic.mapper.DicIndustryMapper;
import com.wigem.dic.vo.DicIndustryVo;
import com.wigem.framework.common.pojo.PageResult;
import com.wigem.framework.mybatis.core.query.LambdaQueryWrapperX;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * 行业字典Service业务层处理
 *
 * @author ZY
 * @date 2021-10-25
 */
@Service
public class DicIndustryServiceImpl implements DicIndustryService {
    @Resource
    private DicIndustryMapper dicIndustryMapper;

    //region 基础方法
    @Override
    public DicIndustryEntity getEntity(String keyValue) {
        return dicIndustryMapper.selectById(keyValue);
    }

    @Override
    public List<DicIndustryEntity> getList(DicIndustryVo dicIndustryVo) {
        return dicIndustryMapper.selectList(query(dicIndustryVo));
    }

    @Override
    public PageResult<DicIndustryEntity> getPageList(DicIndustryVo dicIndustryVo) {
        return dicIndustryMapper.selectPage(dicIndustryVo, query(dicIndustryVo));
    }

    @Override
    public void add(DicIndustryVo dicIndustryVo) {
        DicIndustryEntity dicIndustryEntity = new DicIndustryEntity();
        BeanUtils.copyProperties(dicIndustryVo, dicIndustryEntity);
        dicIndustryEntity.create();
        dicIndustryMapper.insert(dicIndustryEntity);
    }

    @Override
    public void update(DicIndustryVo dicIndustryVo) {
        DicIndustryEntity dicIndustryEntity = new DicIndustryEntity();
        BeanUtils.copyProperties(dicIndustryVo, dicIndustryEntity);
        dicIndustryMapper.updateById(dicIndustryEntity);
    }

    @Override
    public int delete(String keyValue) {
        return dicIndustryMapper.deleteById(keyValue);
    }

    @Override
    public int remove(String keyValue) {
        return dicIndustryMapper.remove(keyValue);
    }


    @Override
    public void save(DicIndustryVo dicIndustryVo) {
        DicIndustryEntity dicIndustryEntity = new DicIndustryEntity();
        BeanUtils.copyProperties(dicIndustryVo, dicIndustryEntity);
        if (StringUtils.isEmpty(dicIndustryVo.getId())) {
            dicIndustryEntity.create();
            dicIndustryMapper.insert(dicIndustryEntity);
        } else {
            dicIndustryMapper.updateById(dicIndustryEntity);
        }
    }

    public LambdaQueryWrapperX<DicIndustryEntity> query(DicIndustryVo dicIndustryVo) {
        LambdaQueryWrapperX<DicIndustryEntity> dicIndustryEntityLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
        dicIndustryEntityLambdaQueryWrapperX = dicIndustryEntityLambdaQueryWrapperX;
        return dicIndustryEntityLambdaQueryWrapperX;
    }
}
